﻿using B.S.BaseData.ErrorCode;
using B.S.BaseData.ErrorCode.ErrorCodes;
using B.S.BaseData.ReadAPI.Applications.Commands.Users;
using B.S.BaseData.ReadAPI.Dtos.Users;
using B.S.DataBase.EFCoreServiers.Dtos.Roles;
using B.S.DataBase.EFCoreServiers.IServices.Roles;
using MediatR;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace B.S.BaseData.ReadAPI.Controllers
{
    /// <summary>
    /// 角色管理
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    [Authorize]
    [ApiExplorerSettings(GroupName = "Roles")]
    public class RoleController : ControllerBase
    {
        private readonly IRoleServices role;
        private readonly ILogger<RoleController> _logger;

        public RoleController(IRoleServices role, ILogger<RoleController> logger)
        {
            this.role = role;
            _logger = logger;
        }
        /// <summary>
        /// 角色列表
        /// </summary>
        /// <param name="roleDto">角色信息</param>
        /// <returns>列表结果</returns>
        [HttpGet]
        public async Task<ApiResult<ApiPaging<GetRoleResponseDto>>> GetRoleListAsync([FromQuery]GetRoleDto roleDto)
        {
            try
            {
                _logger.LogInformation($"角色列表显示成功");
                return await role.GetRoleListAsync(roleDto);
            }
            catch (System.Exception ex)
            {
                _logger.LogError(ex, $"角色列表显示发生异常");
                return ApiResult<ApiPaging<GetRoleResponseDto>>.Fail("角色列表显示发生异常，请稍后重试", StatusCodeEnum.Exception);
            }
        }




    }
}
